package hw;


import Util.Util;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Changepw extends JPanel implements ActionListener {
    private Atm atm;
    private Icon sureImg = Util.getIcon("/buttonSure.jpg");
    private Icon offImg = Util.getIcon("/buttonOff.jpg");
    private JButton sureBtn = new JButton(sureImg);
    private JButton offBtn = new JButton(offImg);
    private JTextField changepw = new JTextField();

    public Changepw(Atm atm) {
        this.atm = atm;
        offBtn.setBounds(930,200,140,50);
        sureBtn.setBounds(680,200,140,50);
        changepw.setBounds(430,200,240,50);
        //添加组件
        this.add(offBtn);
        this.add(sureBtn);
        this.add(changepw);

        //监听绑定
        offBtn.addActionListener(this);
        sureBtn.addActionListener(this);

        this.setLayout(null);
        this.setOpaque(false);

    }
    @Override
    public void actionPerformed(ActionEvent e) {
        Users use = atm.getUser();
        if (e.getSource() == offBtn) {
            atm.switchPanel("menu");
        }
        if (e.getSource()==sureBtn){

            use.setPassword(changepw.getText());
        }




    }
}
